package com.ilong.wehrservice.controller.system.basic;

import com.ilong.wehrservice.model.Position;
import com.ilong.wehrservice.model.RespBean;
import com.ilong.wehrservice.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TOOD
 *
 * @author long
 * @date 2020-06-16 17:07
 */
@RestController
@RequestMapping("/system/basic/pos")
public class PositionController {
    @Autowired
    PositionService positionService;

    @GetMapping("/")
    public List<Position> getAllPositions(){
        return positionService.getAllPositions();
    }

    @PostMapping("/")
    public RespBean addPosition(@RequestBody Position position){
        if (positionService.addPosition(position)==1){
            return RespBean.ok("添加成功!");
        }
        return RespBean.error("添加失败！");
    }

    @PutMapping("/")
    public RespBean updatePositions(@RequestBody  Position position){
        if (positionService.updatePositions(position)==1){
            return RespBean.ok("更新成功！");
        }
        return RespBean.error("更新失败");
    }
    @DeleteMapping("/{id}")
    public RespBean deletePositionById(@PathVariable Integer id){
        if (positionService.deletePositionById(id)==1){
            return RespBean.ok("删除成功！");
        }
        return RespBean.error("删除失败！");
    }

    @DeleteMapping("/")
    public RespBean deletePositionsByids(Integer[] ids){
            if (positionService.deletePositionsByids(ids)==ids.length){
                return RespBean.ok("删除成功！");
            }
            return RespBean.error("删除失败！");
    }

}
